/**
 * Created by hcadmin on 16/3/1.
 */
define([
    "jquery",
    "IO",
    "bootbox"
], function($,IO,bootbox) {
    $(function () {
        var grid;
        //每列数据列性
        var columns = [
            {
                title: '序号',
                dataIndex: 'vocabulary_id',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].vocabulary_id + "</span>";
                }
            },
            {
                title: '词条名称',
                dataIndex: 'vocabulary_content',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].content + "</span>";
                }
            },
            {
                title: '发布时间',
                dataIndex: 'create_date',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].create_date + "</span>";
                }
            },
            {
                title: '评论数',
                dataIndex: 'vocabulary_comment',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].comment_num + "</span>";
                }
            },
            {
                title: '点赞数',
                dataIndex: 'vocabulary_like',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].upvote_num + "</span>";
                }
            },
            {
                title: '操作',
                dataIndex: 'action',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span><a href='javascript:void(0)' style='color: red;' class='delete' act_id='"+data[datarow].vocabulary_id
                    +"'>删除</a>&nbsp&nbsp&nbsp&nbsp<a href='/pte/update_citiao?vocabulary_id="+data[datarow].vocabulary_id
                    +"'style='color: deepskyblue;'>修改</a><br>&nbsp<a href ='/pte/citiao_pinglun?vocabulary_id="
                        + data[datarow].vocabulary_id+"' style='color: orange;'>查看评论</a></span>";
                }
            },

        ];


        //数组初始化

        function dataInit() {
            grid = new Grid("/pte/api/citiao_lb", $("#table_my_toast"), $("#paging_my_toast"), 1, 10, columns, get_input_param(), 10);

            //初始化
            grid.Init();
        }

        //获取输入框内容
        function get_input_param() {

            var content=$("#citiao_content").val();
            var param="content=" +content;
            return param;
        }
        dataInit();
        //查询
        $("#query").bind("click", function () {
            dataInit();
        });
    });
    //删除课程
    $(document).on("click",".delete",function(){
        var act_id=$(this).attr("act_id");
        if(act_id){
            bootbox.confirm("确定要删除该词条？",function(result){
                if(result) {
                    IO.get("act/citiao_delete",{act_id:act_id},function(d){
                        bootbox.alert(d.msg,function(){
                            if (d.code == 0) {
                                location.href = '/pte/citiao_lb';
                            }
                        })
                    });
                }
            });
        }
    });

});